import regex from "@/plugins/regex";
export const initAddUserFrom = {
  username: "",
  password: "",
  email: "",
  fullName: "",
};
/**正则验证 */
const validateUsername = (multiLanguages: any) => {
  return (rule: any, value: string, callback: any) => {
    if (regex.username.test(value)) {
      callback();
    } else {
      callback(new Error(multiLanguages("warning.field_input_error")));
    }
  };
};
const validateEmail = (multiLanguages: any) => {
  return (rule: any, value: string, callback: any) => {
    if (regex.email.test(value)) {
      callback();
    } else {
      callback(new Error(multiLanguages("warning.field_input_error")));
    }
  };
};
/**汇总验证 */
export const checkRules = (multiLanguages: any) => {
  return {
    username: [
      { required: true, message: multiLanguages("warning.account_not_empty"), trigger: "change" },
      { validator: validateUsername(multiLanguages), trigger: "change" },
    ],
    password: [{ required: true, message: multiLanguages("warning.password_not_empty"), trigger: "change" }],
    email: [
      { required: true, message: multiLanguages("warning.field_not_empty"), trigger: "change" },
      { validator: validateEmail(multiLanguages), trigger: "change" },
    ],
    fullName: [{ required: true, message: multiLanguages("warning.field_not_empty"), trigger: "change" }],
  };
};
